package com.soft.javase.day07.balancenotenoughexception;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/26
 */
public class Account {
    private Long id;
    private double balance;

    public Account withdraw(double money) throws BalanceNotEnoughException {
        if (this.balance >= money) {
            this.balance -= money;
            return this;
        }
        throw new BalanceNotEnoughException("余额不足");
    }

    public Account() {
    }

    public Account(Long id, double balance) {
        this.id = id;
        this.balance = balance;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    @Override
    public String toString() {
        return "Account{" +
                "id=" + id +
                ", balance=" + balance +
                '}';
    }
}
